home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / kingobox.c < prev    next >
C/C++ Source or Header  |  2000-05-04  |  8KB  |  322 lines

  1. #include "driver.h"
  2. #include "vidhrdw/generic.h"
  3.  
  4. unsigned char *kingobox_videoram1;
  5. unsigned char *kingobox_colorram1;
  6. size_t kingobox_videoram1_size;
  7. unsigned char *kingobox_scroll_y;
  8.  
  9. extern int kingofb_nmi_enable;
  10.  
  11. static int palette_bank;
  12.  
  13.  
  14.  
  15. /***************************************************************************
  16.  
  17.   Convert the color PROMs into a more useable format.
  18.  
  19.   King of Boxer has three 256x4 palette PROMs, connected to the RGB output
  20.   this way:
  21.  
  22.   bit 3 -- 180 ohm resistor  -- RED/GREEN/BLUE
  23.         -- 360 ohm resistor  -- RED/GREEN/BLUE
  24.         -- 750 ohm resistor  -- RED/GREEN/BLUE
  25.   bit 0 -- 1.5kohm resistor  -- RED/GREEN/BLUE
  26.  
  27.   The foreground color code directly goes to the RGB output, this way:
  28.  
  29.   bit 5 --  51 ohm resistor  -- RED
  30.   bit 4 --  51 ohm resistor  -- GREEN
  31.   bit 3 --  51 ohm resistor  -- BLUE
  32.  
  33. ***************************************************************************/
  34. void kingobox_vh_convert_color_prom(unsigned char *palette,unsigned short *colortable,const unsigned char *color_prom)
  35. {
  36.     int i;
  37.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  38.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  39.  
  40.  
  41.     for (i = 0;i < 256;i++)
  42.     {
  43.         int bit0,bit1,bit2,bit3;
  44.  
  45.  
  46.         /* red component */
  47.         bit0 = (color_prom[0] >> 0) & 0x01;
  48.         bit1 = (color_prom[0] >> 1) & 0x01;
  49.         bit2 = (color_prom[0] >> 2) & 0x01;
  50.         bit3 = (color_prom[0] >> 3) & 0x01;
  51.         *(palette++) = 0x10 * bit0 + 0x21 * bit1 + 0x45 * bit2 + 0x89 * bit3;
  52.         /* green component */
  53.         bit0 = (color_prom[256] >> 0) & 0x01;
  54.         bit1 = (color_prom[256] >> 1) & 0x01;
  55.         bit2 = (color_prom[256] >> 2) & 0x01;
  56.         bit3 = (color_prom[256] >> 3) & 0x01;
  57.         *(palette++) = 0x10 * bit0 + 0x21 * bit1 + 0x45 * bit2 + 0x89 * bit3;
  58.         /* blue component */
  59.         bit0 = (color_prom[2*256] >> 0) & 0x01;
  60.         bit1 = (color_prom[2*256] >> 1) & 0x01;
  61.         bit2 = (color_prom[2*256] >> 2) & 0x01;
  62.         bit3 = (color_prom[2*256] >> 3) & 0x01;
  63.         *(palette++) = 0x10 * bit0 + 0x21 * bit1 + 0x45 * bit2 + 0x89 * bit3;
  64.  
  65.         color_prom++;
  66.     }
  67.  
  68.  
  69.     /* the foreground chars directly map to primary colors */
  70.     for (i = 0;i < 8;i++)
  71.     {
  72.         /* red component */
  73.         *(palette++) = 0xff * ((i >> 2) & 0x01);
  74.         /* green component */
  75.         *(palette++) = 0xff * ((i >> 1) & 0x01);
  76.         /* blue component */
  77.         *(palette++) = 0xff * ((i >> 0) & 0x01);
  78.     }
  79.  
  80.     for (i = 0;i < TOTAL_COLORS(0)/2;i++)
  81.     {
  82.         COLOR(0,2*i+0) = 0;    /* transparent */
  83.         COLOR(0,2*i+1) = 256 + i;
  84.     }
  85. }
  86.  
  87.  
  88. /* Ring King has one 256x8 PROM instead of two 256x4 */
  89. void ringking_vh_convert_color_prom(unsigned char *palette,unsigned short *colortable,const unsigned char *color_prom)
  90. {
  91.     int i;
  92.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  93.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  94.  
  95.  
  96.     for (i = 0;i < 256;i++)
  97.     {
  98.         int bit0,bit1,bit2,bit3;
  99.  
  100.  
  101.         /* red component */
  102.         bit0 = (color_prom[0] >> 4) & 0x01;
  103.         bit1 = (color_prom[0] >> 5) & 0x01;
  104.         bit2 = (color_prom[0] >> 6) & 0x01;
  105.         bit3 = (color_prom[0] >> 7) & 0x01;
  106.         *(palette++) = 0x10 * bit0 + 0x21 * bit1 + 0x45 * bit2 + 0x89 * bit3;
  107.         /* green component */
  108.         bit0 = (color_prom[0] >> 0) & 0x01;
  109.         bit1 = (color_prom[0] >> 1) & 0x01;
  110.         bit2 = (color_prom[0] >> 2) & 0x01;
  111.         bit3 = (color_prom[0] >> 3) & 0x01;
  112.         *(palette++) = 0x10 * bit0 + 0x21 * bit1 + 0x45 * bit2 + 0x89 * bit3;
  113.         /* blue component */
  114.         bit0 = (color_prom[256] >> 0) & 0x01;
  115.         bit1 = (color_prom[256] >> 1) & 0x01;
  116.         bit2 = (color_prom[256] >> 2) & 0x01;
  117.         bit3 = (color_prom[256] >> 3) & 0x01;
  118.         *(palette++) = 0x10 * bit0 + 0x21 * bit1 + 0x45 * bit2 + 0x89 * bit3;
  119.  
  120.         color_prom++;
  121.     }
  122.  
  123.  
  124.     /* the foreground chars directly map to primary colors */
  125.     for (i = 0;i < 8;i++)
  126.     {
  127.         /* red component */
  128.         *(palette++) = 0xff * ((i >> 2) & 0x01);
  129.         /* green component */
  130.         *(palette++) = 0xff * ((i >> 1) & 0x01);
  131.         /* blue component */
  132.         *(palette++) = 0xff * ((i >> 0) & 0x01);
  133.     }
  134.  
  135.     for (i = 0;i < TOTAL_COLORS(0)/2;i++)
  136.     {
  137.         COLOR(0,2*i+0) = 0;    /* transparent */
  138.         COLOR(0,2*i+1) = 256 + i;
  139.     }
  140. }
  141.  
  142.  
  143.  
  144. WRITE_HANDLER( kingofb_f800_w )
  145. {
  146.     kingofb_nmi_enable = data & 0x20;
  147.  
  148.     if (palette_bank != ((data & 0x18) >> 3))
  149.     {
  150.         palette_bank = (data & 0x18) >> 3;
  151.         memset(dirtybuffer,1,videoram_size);
  152.     }
  153. }
  154.  
  155.  
  156.  
  157. void kingobox_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  158. {
  159.     int offs;
  160.  
  161.  
  162.  
  163.     /* background */
  164.  
  165.     /* for every character in the Video RAM, check if it has been modified */
  166.     /* since last time and update it accordingly. */
  167.     for (offs = videoram_size - 1;offs >= 0;offs--)
  168.     {
  169.         if (dirtybuffer[offs])
  170.         {
  171.             int sx,sy,code,bank;
  172.  
  173.  
  174.             sx = offs / 16;
  175.             sy = 15 - offs % 16;
  176.  
  177.             dirtybuffer[offs] = 0;
  178.  
  179.             code = videoram[offs] + ((colorram[offs] & 0x03) << 8);
  180.             bank = (colorram[offs] & 0x04) >> 2;
  181.  
  182.             drawgfx(tmpbitmap,Machine->gfx[2 + bank],
  183.                     code,
  184.                     ((colorram[offs] & 0x70) >> 4) + 8 * palette_bank,
  185.                     0,0,
  186.                     sx*16,sy*16,
  187.                     0,TRANSPARENCY_NONE,0);
  188.         }
  189.     }
  190.  
  191.     {
  192.         int scrolly = kingobox_scroll_y[0];
  193.  
  194.         copyscrollbitmap(bitmap,tmpbitmap,0,0,1,&scrolly,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  195.     }
  196.  
  197.  
  198.     /* sprites */
  199.     for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
  200.     {
  201.         int sx,sy,code,color,bank,flipy;
  202.  
  203.  
  204.         sx = spriteram[offs+1];
  205.         sy = spriteram[offs];
  206.  
  207.         code = spriteram[offs + 2] + ((spriteram[offs + 3] & 0x03) << 8);
  208.         bank = (spriteram[offs + 3] & 0x04) >> 2;
  209.         color = ((spriteram[offs + 3] & 0x70) >> 4) + 8 * palette_bank,
  210.         flipy = spriteram[offs + 3] & 0x80;
  211.  
  212.         drawgfx(bitmap,Machine->gfx[2 + bank],
  213.                     code,
  214.                     color,
  215.                     0,flipy,
  216.                     sx,sy,
  217.                     0,TRANSPARENCY_PEN,0);
  218.     }
  219.  
  220.  
  221.     /* foreground */
  222.     for (offs = kingobox_videoram1_size - 1;offs >= 0;offs--)
  223.     {
  224.         int sx,sy,code,bank;
  225.  
  226.  
  227.         sx = offs / 32;
  228.         sy = 31 - offs % 32;
  229.  
  230.         code = kingobox_videoram1[offs] + ((kingobox_colorram1[offs] & 0x01) << 8);
  231.         bank = (kingobox_colorram1[offs] & 0x02) >> 1;
  232.  
  233.         drawgfx(bitmap,Machine->gfx[bank],
  234.                 code,
  235.                 (kingobox_colorram1[offs] & 0x38) >> 3,
  236.                 0,0,
  237.                 sx*8,sy*8,
  238.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  239.     }
  240. }
  241.  
  242. void ringking_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  243. {
  244.     int offs;
  245.  
  246.  
  247.  
  248.     /* background */
  249.  
  250.     /* for every character in the Video RAM, check if it has been modified */
  251.     /* since last time and update it accordingly. */
  252.     for (offs = videoram_size - 1;offs >= 0;offs--)
  253.     {
  254.         if (dirtybuffer[offs])
  255.         {
  256.             int sx,sy;
  257.  
  258.  
  259.             sx = offs / 16;
  260.             sy = 15 - offs % 16;
  261.  
  262.             dirtybuffer[offs] = 0;
  263.  
  264.             drawgfx(tmpbitmap,Machine->gfx[4],
  265.                     videoram[offs],
  266.                     ((colorram[offs] & 0x70) >> 4 ) + 8 * palette_bank,
  267.                     0,0,
  268.                     sx*16,sy*16,
  269.                     0,TRANSPARENCY_NONE,0);
  270.         }
  271.     }
  272.  
  273.     {
  274.         int scrolly = kingobox_scroll_y[0];
  275.  
  276.         copyscrollbitmap(bitmap,tmpbitmap,0,0,1,&scrolly,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  277.     }
  278.  
  279.  
  280.     /* sprites */
  281.     for (offs = 0; offs < spriteram_size;offs += 4)
  282.     {
  283.         int sx,sy,code,color,bank,flipy;
  284.  
  285.         sx = spriteram[offs+2];
  286.         sy = spriteram[offs];
  287.  
  288.         code = spriteram[offs + 3] + ((spriteram[offs + 1] & 0x03) << 8);
  289.         bank = (spriteram[offs + 1] & 0x04) >> 2;
  290.         color = ((spriteram[offs + 1] & 0x70) >> 4) + 8 * palette_bank,
  291.         flipy = ( spriteram[offs + 1] & 0x80 ) ? 0 : 1;
  292.  
  293.         drawgfx(bitmap,Machine->gfx[2 + bank],
  294.                     code,
  295.                     color,
  296.                     0,flipy,
  297.                     sx,sy,
  298.                     0,TRANSPARENCY_PEN,0);
  299.     }
  300.  
  301.  
  302.     /* foreground */
  303.     for (offs = kingobox_videoram1_size - 1;offs >= 0;offs--)
  304.     {
  305.         int sx,sy,code,bank;
  306.  
  307.  
  308.         sx = offs / 32;
  309.         sy = 31 - offs % 32;
  310.  
  311.         code = kingobox_videoram1[offs] + ((kingobox_colorram1[offs] & 0x01) << 8);
  312.         bank = (kingobox_colorram1[offs] & 0x02) >> 1;
  313.  
  314.         drawgfx(bitmap,Machine->gfx[bank],
  315.                 code,
  316.                 (kingobox_colorram1[offs] & 0x38) >> 3,
  317.                 0,0,
  318.                 sx*8,sy*8,
  319.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  320.     }
  321. }
  322.